home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / Bonus / Plasmatech / ptscp_examples.exe / %MAINDIR% / Examples / ImageCombo / Delphi / FMain.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-08-31  |  2.8 KB  |  103 lines

  1. unit FMain;
  2.  
  3. interface
  4. uses
  5.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   StdCtrls, UPTImageCombo, UPTFrame;
  7.  
  8. type
  9.   TFrmMain = class(TForm)
  10.     PTImageCombo1: TPTImageCombo;
  11.     PTFrame1: TPTFrame;
  12.     PTFrame4: TPTFrame;
  13.     PTFrame2: TPTFrame;
  14.     PTFrame3: TPTFrame;
  15.     ImageList1: TImageList;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure PTImageCombo1SelEndOk(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   FrmMain: TFrmMain;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. function GetIcon( hInst: THandle;  id, size: Integer;  icon: TIcon ): TIcon;
  32. begin // Retrieve an icon from a given module instance
  33.   icon.Handle := Windows.LoadImage( hInst, MAKEINTRESOURCE(id), IMAGE_ICON, size,size, 0 );
  34.   result := icon;
  35. end;
  36.  
  37.  
  38. procedure TFrmMain.FormCreate(Sender: TObject);
  39. var i: TIcon;
  40.     item: TPTImageComboItem;
  41. begin
  42.  //-- Create image list and load 16x16 icons from resources
  43.   i := TIcon.Create;
  44.   try
  45.     ImageList1.AddIcon( GetIcon(HInstance, 100, 16, i) );
  46.     ImageList1.AddIcon( GetIcon(HInstance, 101, 16, i) );
  47.     ImageList1.AddIcon( GetIcon(HInstance, 102, 16, i) );
  48.   finally
  49.     i.Free;
  50.   end;
  51.  
  52.  //-- Fill the image combo with some data items, and associate a frame control with
  53.  //-- each entry via the item.Data property.
  54.   item := PTImageCombo1.AddItem( 'First Item', 0, 0 );
  55.   item.Data := PTFrame1;
  56.  
  57.   item := PTImageCombo1.AddItem( 'Second Item', 1, 1 );
  58.   item.Data := PTFrame2;
  59.  
  60.   item := PTImageCombo1.AddItem( 'Third Item', 2, 2 );
  61.   item.Data := PTFrame3;
  62.  
  63.   item := PTImageCombo1.AddItem( 'Fourth Item', 1, 1 );
  64.   item.Data := PTFrame4;
  65.  
  66.  //-- Start with something selected
  67.   PTImageCombo1.ItemIndex := 0;
  68. end;
  69.  
  70.  
  71. { This event is called after a 'successful' selection by the user.
  72.   * It is not called when the combo item is changed programatically.
  73.   * It is not called if the user presses 'Esc' or moves to another control while the combo is dropped down.
  74.   * It is not called as the user moves up and down with the arrow keys.
  75.  
  76.   * It IS called if the user drops down the list and selects an item with the mouse.
  77.   * It IS called when the user presses the Enter key on a new item.
  78.  
  79.   This is how the comboboxes in Explorer and Internet Explorer behave.
  80.  
  81.   This event just toggles the color of the frame control associated with the newly selected item.
  82. }
  83. procedure TFrmMain.PTImageCombo1SelEndOk(Sender: TObject);
  84. var itemd: TPTFrame;
  85. begin
  86.   itemd := TObject(PTImageCombo1.ImageComboItem[PTImageCombo1.ItemIndex].Data) as TPTFrame;
  87.   if itemd.Tag=0 then
  88.   begin
  89.     itemd.Tag := 1;
  90.     itemd.Color := clRed;
  91.   end
  92.   else
  93.   begin
  94.     itemd.Tag := 0;
  95.     itemd.Color := clBtnFace;
  96.   end;
  97. end;
  98.  
  99.  
  100.  
  101.  
  102. end.
  103.